/*
 DiscoverDevices
 Shows how to discover other bluetooth devices 
 
 GNU GPL
 Copyright (c) 2012 Marlon J. Manrique       
 http://www.marlonj.com 
 $Id$
*/

// Import the the bluetooth library  
import com.marlonj.processing.abluetooth.*;

// Object to control the bluetooth 
ABluetooth bluetooth;

// The message to show 
String statusMessage = "Touch the Screen to Discover Devices"; 

/**
 * Create the bluetooth library 
 */
void setup() {
  // Create the bluetoot library 
  bluetooth = new ABluetooth(this);

  textAlign(CENTER);  
}

/**
 * Draw the name and address of the bluetoot adapter
 */ 
void draw() {  
  // Clear the screen
  background(0);
  
  // Draw to time bigger the text 
  scale(2);
  
  // Show the status message 
  text(statusMessage, width/4, height/4);
}

/**
 * Start the discover devices 
 */
void mousePressed() {
  startSearching();
}

/**
 * A device was found 
 *
 * @param device Information of the device 
 */
void deviceDiscovered(ABluetoothDevice device) {
  // Show the device name 
  statusMessage = device.name();
}

/**
 * The discover service ended  
 */
void discoveryEnded() {
  statusMessage = "Touch the Screen to Discover Devices";
}

/**
 * Start searching devices 
 */
void startSearching() {
  // If the bluetooh is active try to find devices 
  if(bluetooth.isEnabled()) {
    bluetooth.discover();
    statusMessage = "Searching ...";
  } else {
    statusMessage = "Bluetooth Not Enable";    
  }
} 
